import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
		'upUserInfo'
    ]),
	_previewImage(image) {
		var imgArr = [];
		imgArr.push(image);
		//预览图片
		uni.previewImage({
			urls: imgArr,
			current: imgArr[0]
		});
	},
	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/info',
			params: {
	
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
	//删除一天
	deleteData(id,index){
		let that = this
		that.$toast.confirm({
			content: '确定删除？',
			callback: result => {
				if (result) {
					
					that.$httpRequest.get({
						that: that,
						url: 'h5/deleteData',
						params: {
							date:that.$utils.getNowFormatDate()
						},
						success: res => {
							if (res.code === that.$httpConfig.SUCCESS_CODE) {
								that.list.splice(index,1)
							} else {
								that.$toast.msg(res.message, {
								    icon: 1
								})
							}
						}
					})
				}
			}
		})
	},
	//删除想法
	deleteThought(id,index,parentIndex){
		let that = this
		that.$toast.confirm({
			content: '确定删除？',
			callback: result => {
				if (result) {
					
					that.$httpRequest.request({
						that: that,
						url: 'h5/deleteThought',
						params: {
							id
						},
						success: res => {
							if (res.code === that.$httpConfig.SUCCESS_CODE) {
								that.list[parentIndex].thoughts.splice(index,1)
							} else {
								that.$toast.msg(res.message, {
								    icon: 1
								})
							}
						}
					})
				}
			}
		})
		
	},
	
	getPageList(id) {
		let that = this
		if (that.loading) {
			return false
		}
		let params = {}
		params.pageNo = that.page,
		params.pageSize =that.list_rows,
		that.loading = true
		that.$httpRequest.get({
			that: that,
			url: 'h5/getEveryoneRecordPage',
			params: params,
			success: res => {
				that.loading = false
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					if (that.page === 1) {
						that.list = res.data.rows
					} else {
						that.list = that.list.concat(res.data.rows)
					}
					that.page++
				} else {
					
				}
			}
		})
	},
	close(){
		this.$refs.sendPopup.close()
	},
	//添加评论
	addComment() {
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/addComment',
			params: {
				content:that.comment_content,
				thoughtId:that.thoughtId
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.comment_content = ''
					that.list[that.current_list_index].thoughts[that.current_thought_index].commentList.push(res.data)
					that.close()
				} else {
					
				}
			}
		})
	},
	favoriteThought(id,index,parentIndex) {
		this.current_thought_index = index //当前想法的索引
		this.current_list_index = parentIndex //当前页面列表的索引
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/favoriteThought',
			params: {
				thoughtId:id
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.list[that.current_list_index].thoughts[that.current_thought_index].favoriteUserList.push(res.data)
				} else {
					that.$toast.msg(res.message, {
					    icon: 1
					})
				}
			}
		})
	},
	toComment(id,index,parentIndex){
		this.thoughtId = id
		this.current_thought_index = index //当前想法的索引
		this.current_list_index = parentIndex //当前页面列表的索引
		this.$refs.sendPopup.open()
	}

}